// Copyright (c) 2008 Matthew Johnson
// Licensed under the MIT License (see license.txt)
package actionml.core {
	import actionml.Global;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	
	public class StringPathMethods {
		public static function initialize() {
			Global.initializeExtension(StringPathMethods, String);
		}
		public static var instanceMethods:Object = {
			moveUp: function(distance:int = 1) {
				var r:String = this;
				for (var i = 0; i < distance; i++) {	
					r = r.replace(/\/[^\/]*$/, "");
				}
				return r;
			}, 
			appendPath: function(p:String) {
				var r:String = this;
				while(/^\.\.\/ /x.test(p)) {
					r = r.moveUp();
					p = p.replace("../", "");
				}
				if (p.length > 0) {
					return r + "/" + p;
				} else {
					return r;
				}
			},
			removeExtension: function() {
				return this.replace(/\.[^.]*$/, "");
			}, 
			replaceExtension: function(newExtension:String) {
				return this.removeExtension() + "." + newExtension;
			}
		};
	}
}